val input = TextIO.openIn("input.txt");

fun printInt (a:int) =
    print(Int.toString(a)^" ");

fun getInt () =
    Option.valOf (TextIO.scanStream (Int.scan StringCvt.DEC) input);
    
fun printIntList ( [] ) = ()
  | printIntList ( x::xs ) = 
    let
	val tmp = printInt(x)
    in
	printIntList(xs)
    end;

fun getIntList ( 0 ) = []
  | getIntList ( N:int) = getInt()::getIntList(N-1);

fun double (0 : int) : int = 0
    | double n = 2 + double (n - 1);

(*begin*)
fun thenAddOne(f, x) = 1 + f(x)
fun mapList(f, []) = []
    | mapList(f, x::L) = f(x)::mapList(f, L);
(* ? *)
fun mapList2 f [] = []
  | mapList2 f (x::L) = f(x) :: mapList2 f L;
(*end*)

val INPUT = getIntList(6);
printIntList (mapList (double, INPUT));
printIntList (mapList2 double INPUT);